﻿#region License
/* ---------------------------------------------------------------- *
 *
 * This file is part of the Xcoordination Application Space
 * ("XcoAppSpace") http://www.xcoordination.com
 *
 * Copyright (C) 2009 Xcoordination http://www.xcoordination.com
 *
 * XcoAppSpace is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General
 * Public License as published by the Free Software Foundation.
 *
 * XcoAppSpace is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 * or write to the Free Software Foundation, Inc., 51 Franklin
 * Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ---------------------------------------------------------------- */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BruteForceSerializer.Contract;
using BruteForceSerializer.Contract.Internal;

namespace BruteForceSerializer.Normalization
{
    internal class NormalizedField : INormalizedField
    {
        public NormalizedField(string name, object value)
        {
            this.Name = name;
            this.Value = value;
        }

        public string Name { get; private set;}
        public object Value { get; private set;}
    }


    internal class NormalizedReference : INormalizedReference
    {
        public NormalizedReference(int objectIndex)
        {
            this.ObjectId = objectIndex;
        }

        public int ObjectId { get; private set; }
    }


    internal class NormalizedObject : INormalizedObject
    {
        private readonly IList<INormalizedField> fields;


		//public NormalizedObject(Type objectType, int objectId) : this(TypeResolver.TypeToString(objectType), objectId)
		//{
		//}

		public NormalizedObject(string typename, int objectId)
		{
			this.Id = objectId;
			this.Typename = typename;
			this.fields = new List<INormalizedField>();
		}


		//public void AddArrayDescription(Array array)
		//{
		//    for(int i=0; i<array.Rank; i++)
		//    {
		//        this.Typename += i == 0 ? "=" : ",";
		//        this.Typename += array.GetLength(i);
		//    }
		//}

        public void AddField(string name, object value)
        {
            this.fields.Add(new NormalizedField(name, value));
        }


        #region INormalizedObject Members

        public int Id { get; private set; }
        public string Typename { get; private set; }

        public IEnumerable<INormalizedField> Fields
        {
            get { return this.fields; }
        }

        #endregion
    }


}
